const app = getApp()

Page({
  data: {
  },

  onLoad: function (params) {
    var me = this;
    var redirectUrl = params.redirectUrl;
    // debugger;
    if (redirectUrl != null && redirectUrl != undefined && redirectUrl != '') {
      redirectUrl = redirectUrl.replace(/#/g, "?");
      redirectUrl = redirectUrl.replace(/@/g, "=");

      me.redirectUrl = redirectUrl;
    }
  },

  //登录
  doLogin:function(e){
    var formObject=e.detail.value;
    var username = formObject.username;
    var password = formObject.password;

    if (username.length == 0 || password.length == 0) {
      wx.showToast({
        title: '用户名或密码不能为空',
        icon: 'none',
        duration: 3000
      })
    }else{
      var serverUrl = app.serverUrl;
      //调用后台接口
      wx.request({
        url: serverUrl + '/login',
        method:'POST',
        data:{
          username: username,
          password: password 
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        success:function(res){
          console.log(res.data);
          var status = res.data.status;
          if (status == 200) {
            wx.showToast({
              title: '登录成功',
              icon: 'none',
              duration: 3000
            }),
              app.userInfo = res.data.data;
            wx.navigateTo({
              url: '../mine/mine',
            })
          } else if (status == 500) {
            wx.showToast({
              title: res.data.msg,
              icon: 'none',
              duration: 3000
            })
          }

        }
      })
    }
  },
  goRegistPage:function(){
    wx.navigateTo({
      url: '../userRegist/regist',
    })
  }
  
})